#pragma once
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using namespace std;


class InetAddr {
public :
    InetAddr(const struct sockaddr_in& addr) 
        :_addr(addr)
    {
        _ip = inet_ntoa(addr.sin_addr); // 网络序列转主机序列
        _port = ntohs(addr.sin_port);
    }

    string get_info() {
        return "[" + _ip + ":" + to_string(_port) + "]";
    }

    bool operator==(const InetAddr& addr) {
        return this->_ip == addr._ip && this->_port == addr._port;
    }

    struct sockaddr_in& addr() {
        return _addr;
    }
    ~InetAddr() {

    }
private :
    string _ip;
    uint16_t _port;
    struct sockaddr_in _addr;
};

